﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.Navigation;
using Microsoft.SharePoint.WebControls;

namespace INdT_Sharepoint.Breadcrumb
{

    public class Breadcrumb : UserControl
    {
        protected SiteMapPath ContentMap;

        public Breadcrumb()
        {
            Load += BreadcrumbLoad;
        }

        void BreadcrumbLoad(object sender, EventArgs e)
        {
            if (Page is UnsecuredLayoutsPageBase)
            {
                ContentMap.SiteMapProvider = "SPXmlContentMapProvider";
            }
            else if (Page is PublishingLayoutPage)
            {
                ContentMap.RenderCurrentNodeAsLink = false;

                var provider =
                    SiteMap.Providers["CurrentNavSiteMapProviderNoEncode"] as
                    PortalSiteMapProvider;

                if (provider != null)
                {
                    provider.IncludePages =
                        PortalSiteMapProvider.IncludeOption.Always;
                    ContentMap.Provider = provider;
                }
                else
                {
                    ContentMap.SiteMapProvider =
                        "CurrentNavSiteMapProviderNoEncode";
                }
            }
            else
            {
                ContentMap.SiteMapProvider = "SPContentMapProvider";
            }
        }
    }

}
